主题
设置摄像头格式 - SetCameraFormat
函数简介
修改已打开摄像头的像素大小、帧率和 FOURCC。句柄须由 OpenCamera、OpenCameraByName 或 OpenCameraEx 得到。
多数 USB / 采集卡改分辨率会重开设备。成功后用 GetVideoWidth / GetVideoHeight 读取实际值。
本接口只作用于视频句柄,不改变 BindWindowEx display="camera" 的绑定会话。绑定会话的分辨率在绑定时由 SetConfig 的 CameraWidth / CameraHeight / CameraFps / CameraFourcc 决定。
接口名称
SetCameraFormatDLL调用
c
int32_t SetCameraFormat(int64_t instance, int64_t videoHandle, int32_t width, int32_t height, double fps, const char* fourcc);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| videoHandle | 长整数型 | 摄像头视频句柄。传入视频文件句柄会失败。 |
| width | 整数型 | 请求像素宽。0 表示保持当前值。 |
| height | 整数型 | 请求像素高。0 表示保持当前值。 |
| fps | 双精度浮点数 | 请求帧率。0 表示保持当前值。 |
| fourcc | 文本型 | 请求像素格式,如 "MJPG"。空字符串表示保持当前值。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long handle = ola.OpenCamera(0);
int ret = ola.SetCameraFormat(handle, 1280, 720, 30.0, "MJPG");csharp
using OLAPlug;
var ola = new OLAPlugServer();
long handle = ola.OpenCamera(0);
int ret = ola.SetCameraFormat(handle, 1280, 720, 30.0, "MJPG");python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
handle = ola.OpenCamera(0)
ret = ola.SetCameraFormat(handle, 1280, 720, 30.0, "MJPG")java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
long handle = ola.OpenCamera(0);
int ret = ola.SetCameraFormat(handle, 1280, 720, 30.0, "MJPG");go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
handle := ola.OpenCamera(0)
ret := ola.SetCameraFormat(handle, 1280, 720, 30.0, "MJPG")rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let handle = ola.open_camera(0);
let ret = ola.set_camera_format(handle, 1280, 720, 30.0, "MJPG");cpp
var ola = com("OlaPlug.OlaSoft")
var handle = ola.OpenCamera(0)
var ret = ola.SetCameraFormat(handle, 1280, 720, 30.0, "MJPG")vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
handle = ola.OpenCamera(0)
ret = ola.SetCameraFormat(handle, 1280, 720, 30.0, "MJPG")text
.局部变量 ola, OLAPlug
ola.创建 ()
handle = ola.OpenCamera(0)
ret = ola.SetCameraFormat(handle, 1280, 720, 30.0, "MJPG")aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var handle = ola.OpenCamera(0);
var ret = ola.SetCameraFormat(handle, 1280, 720, 30.0, "MJPG");text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 handle = ola.OpenCamera(0)
整数 ret = ola.SetCameraFormat(handle, 1280, 720, 30.0, "MJPG")cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long handle = ola.OpenCamera(0);
int ret = ola.SetCameraFormat(handle, 1280, 720, 30.0, "MJPG");原生 DLL 调用
cpp
SetCameraFormat(instance, videoHandle, 1280, 720, 30.0, "MJPG");csharp
using System.Runtime.InteropServices;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int SetCameraFormat(long ola, long videoHandle, int width, int height, double fps, string fourcc);
SetCameraFormat(instance, videoHandle, 1280, 720, 30.0, "MJPG");python
from ctypes import CDLL, c_int, c_int64, c_double, c_char_p
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
ola.SetCameraFormat.restype = c_int
ola.SetCameraFormat.argtypes = [c_int64, c_int64, c_int, c_int, c_double, c_char_p]
ola.SetCameraFormat(instance, video_handle, 1280, 720, 30.0, b"MJPG")返回值
| 返回值 | 说明 |
|---|---|
1 | 成功。 |
0 | 失败。句柄无效、不是摄像头,或设备拒绝该格式。 |
注意事项
| 项目 | 说明 |
|---|---|
| 只接受摄像头句柄 | 视频文件句柄返回 0。 |
| 读实际值 | 成功后宽高以首帧为准,比驱动属性更可靠。 |
| 可选规格 | 绑定或打开前用 EnumCameras 查看驱动报告的 formats。 |
